<?php

namespace app\models;

use Yii;
use yii\db\ActiveRecord;

class typeState extends ActiveRecord{
    
	public static function tableName(){
	      return "{{%typeState}}";
		  }
		  
   /** public function rules(){
	            return[
				    ['openid','required','message' => 'openid不能为空'],
					['topicCount','required','message' => '题目数量不能为空'],
					['score','required','messaage' => '该类题目总积分不能为空'],
				];
			}*/
       //初始化typeState表	
    public function inite($data){
	if($data){
	   //数据: 输入到数据库中
	   $this->typeId = $data['typeId'];
	   $this->topicCount = $data['topicCount'];
	   $this->score = $data['score'];
	   $result = $this->save();
	   if($result){
		$error = 0;
		return $error;
	   } else{
		$error = $this->getErrors();
		return $error;
	  }
	}else{
		$error = 2;
		return $error;
	   }
	}			
        //更新typeState表(作废)
    public function add($data){
         if($data){
             //处理数据:update
             $this->typeId = $data['typeId'];
             $this->openid = $data['openid'];
             $this->completedTopicCount = $data['completedTopicCount'];
             $this->completedScore = $data['completedScore'];
             
             $result=$this->save();
             if($result){
                $error = 0;
                return $error; 
           } else{ 
                $error = $this->getErrors();
                return $error; 
          }       
        }else{  
                $error = 2;
                return $error; 
           }       
        }

}
